package CarLease.service;

import CarLease.entity.Bus;
import CarLease.entity.Truck;
import CarLease.entity.Van;

import java.util.Scanner;

// 主程序入口
public class Main {
    public static void main(String[] args) {
        // 创建 RentalSystem 对象
        RentalSystem rentalSystem = new RentalSystem();
        // 创建 Scanner 对象用于读取用户输入
        Scanner scanner = new Scanner(System.in);

        while (true) {
            // 打印菜单
            rentalSystem.printMenu();
            System.out.print("请输入你的选择：");
            // 读取用户输入
            String input = scanner.nextLine().trim();
            int choice;

            // 尝试将输入转换为整数
            try {
                choice = Integer.parseInt(input);
            } catch (NumberFormatException e) {
                System.out.println("输入错误！请输入一个整数。");
                continue; // 跳过本次循环，重新输入
            }
            switch (choice) {
                case 1://添加汽车
                    System.out.print("请输入汽车ID：");
                    String carId = scanner.next();
                    System.out.print("请输入汽车型号：");
                    String model = scanner.next();
                    System.out.print("请输入汽车颜色：");
                    String color = scanner.next();
                    System.out.print("请输入汽车价格：");
                    double price = scanner.nextDouble();
                    System.out.print("请输入汽车排量：");
                    double displacement = scanner.nextDouble();

                    //输入汽车类型
                    System.out.print("请输入汽车类型（1：公共汽车，2：卡车，3：货车）：");
                    int type = scanner.nextInt();

                    //根据汽车类型创建汽车对象
                    switch (type){
                        case 1:
                            System.out.println("输入座位数：");
                            int Seatnum = scanner.nextInt();
                            rentalSystem.addCar(new Bus(carId,model,color,price,displacement,Seatnum));
                            break;
                        case 2:
                            System.out.println("输入车厢大小：");
                            double Trunksize = scanner.nextDouble();
                            rentalSystem.addCar(new Van(carId,model,color,price,displacement,Trunksize));
                            break;
                        case 3:
                            System.out.println("输入载重：");
                            double load = scanner.nextDouble();
                            rentalSystem.addCar(new Truck(carId,model,color,price,displacement,load));
                            break;
                        default:
                            System.out.println("输入错误！");
                    }
                    break;
                case 2://查看汽车列表
                    System.out.println("请选择排序方式（1：价格，2：车牌号，3：排量）：");
                    int sortBy = scanner.nextInt();
                    rentalSystem.viewCars(sortBy == 1 ? "price" : sortBy == 2 ? "CardId" : "displacement");
                    break;
                case 3://删除汽车
                    System.out.print("请输入汽车ID：");
                    String deleteCarId = scanner.next();
                    rentalSystem.deleteCar(deleteCarId);
                    break;
                case 4://租车
                    System.out.print("请输入汽车车牌号：");
                    String licensePlate = scanner.next();
                    System.out.print("请输入租车天数：");
                    int days = scanner.nextInt();
                    rentalSystem.rentCar(licensePlate,days);
                    break;
                case 5://还车
                    System.out.print("请输入汽车车牌号：");
                    String returnLicensePlate = scanner.next();
                    rentalSystem.returnCar(returnLicensePlate);
                    break;
                case 0://退出程序
                    System.out.println("感谢使用租车系统！");
                    System.exit(0);
                    break;
                default:
                    System.out.println("无效的选择，请重新输入！");
            }
            }
        }
}
